package org.example.util;

import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.example.annotation.BMyBean;
import org.example.applicationListener.CustomEventPublisher;
import org.example.service.MyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.Map;
@RestController
@Slf4j
public class Controller {

    @Autowired
    private KafkaService kafkaService;

    @Autowired
    private BMyBean bMyBean;

    @Autowired
    private MyService myService;

    @PostMapping(value = "/index")
    public String fun(@RequestBody Map<String,Map> map){
        //bMyBean.fun();
       /* log.info("访问fun方法");
        log.error("异常错误");
        Map value = map.get("value");
        String jsonStr = JSONUtil.toJsonStr(value);
        kafkaService.sendMessage(jsonStr);*/
        log.info(JSONUtil.toJsonStr(myService));
        return "fun";
    }

    @Autowired
    private CustomEventPublisher customEventPublisher;

    @GetMapping(value = "/index1")
    public String fun(){
        customEventPublisher.publishCustomEvent("hello呀");
        return "fun";
    }

    @PostConstruct
    public void created(){
        System.out.println("postconstruct created");
    }

    @PreDestroy
    public void destroyFun(){
        System.out.println("Controller id destory");
        OkUtils.fun();
    }
}
